1398D - Colored Rectangles - CodeForces Solution


dp greedy sortings *1800

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define pb push_back
using namespace std;
    vector<int> r;
    vector<int> g;
    vector<int> b;
    ll res[201][201][201];
    ll dp(int re,int gr,int bl){
        if(res[re][gr][bl]){
            return res[re][gr][bl];
        }
        ll pom,res1,res2,res3;
        if(re>0&&gr>0)
            res1=dp(re-1,gr-1,bl)+r[re-1]*g[gr-1];
        else
            res1=0;
        if(re>0&&bl>0)
            res2=dp(re-1,gr,bl-1)+r[re-1]*b[bl-1];
        else
            res2=0;
        if(gr>0&&bl>0)
            res3=dp(re,gr-1,bl-1)+g[gr-1]*b[bl-1];
        else
            res3=0;
        res[re][gr][bl]=max(res1,max(res2,res3));
        return res[re][gr][bl];
    }
void solve() {
    int r_,g_,b_;
    cin>>r_>>g_>>b_;
    int pom;
    for(int i=0;i<r_;i++){
        cin>>pom;
        r.pb(pom);
    }
    for(int i=0;i<g_;i++){
        cin>>pom;
        g.pb(pom);
    }
    for(int i=0;i<b_;i++){
        cin>>pom;
        b.pb(pom);
    }
    sort(r.begin(),r.end());
    sort(g.begin(),g.end());
    sort(b.begin(),b.end());
    for(int i=0;i<r_;i++){
        for(int j=0;j<g_;j++){
            for(int k=0;k<b_;k++){
                res[i][j][k]=0;
            }
        }
    }
    for(int i=0;i<r_;i++){
        res[i][0][0]=0;
    }
    for(int i=0;i<g_;i++){
        res[0][i][0]=0;
    }
    for(int i=0;i<b_;i++){
        res[0][0][i]=0;
    }
    pom=dp(r_,g_,b_);
    cout<<pom<<endl;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //FILES
    int t=1;
    /*
    cin>>t;
    //*/
    while(t--) {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments